<?php
/**
 * @package		简易CMS
 * @subpackage	后台菜单定义
 * @version		$Id: admincp_menu.php 23 2012-06-11 18:04:03Z htmambo@gmail.com $
 * @author		Hoping
 * @copyright	Copyright (C) 2010 Hoping Software Studio.
 */

global $_G;
if(!defined('IN_JYCMS') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

$isfounder = isset($isfounder) ? $isfounder : isfounder();

$topmenu = $menu = array();

$topmenu = array (
	'index' => '',
	'global' => '',
	'style' => '',
	'user' => '',
	'portal' => '',
	'extended' => '',
	'tools' => '',
);

$menu['index'] = array(
	array('menu_home', 'index'),
	array('menu_custommenu_manage', 'misc_custommenu'),
);

$custommenu = get_custommenu();
$menu['index'] = array_merge($menu['index'], $custommenu);

$menu['global'] = array(
	array('menu_setting_basic', 'setting_basic'),
	array('menu_setting_access', 'setting_access'),
	array('menu_setting_optimize', 'setting_seo'),
	array('menu_setting_functions', 'setting_functions'),
	array('menu_setting_sec', 'setting_sec'),
	array('menu_setting_datetime', 'setting_datetime'),
	array('menu_setting_attachments', 'setting_attach'),
	array('menu_setting_imgwater', 'setting_imgwater'),
	array('menu_setting_search', 'setting_search'),
	array('menu_setting_ranklist', 'setting_ranklist'),
	array('menu_posting_censors', 'misc_censor'),
);

$menu['style'] = array(
	array('menu_setting_customnav', 'nav_headernav'),
	array('menu_setting_styles', 'setting_styles'),
	array('menu_styles', 'styles'),
	$isfounder ? array('menu_styles_templates', 'templates') : null,
	array('menu_click', 'click')
);

$menu['user'] = array(
	array('menu_members_edit', 'members_search'),
	array('menu_members_add', 'members_add'),
	array('menu_members_ipban', 'members_ipban'),
	array('menu_admingroups', 'admingroup'),
	array('menu_usergroups', 'usergroups'),
);

$menu['portal'] = array(
	array('menu_portalcategory', 'portalcategory'),
	array('menu_article', 'article'),
	array('menu_blockstyle', 'blockstyle'),
	array('menu_block', 'block'),
	array('menu_diytemplate', 'diytemplate'),
	array('menu_maint_attaches', 'attach'),
	array('menu_maint_comment', 'comment'),
	array('Customfields', 'customfields'),
);

$menu['extended'] = array(
	array('menu_maint_report', 'report'),
	array('menu_adv_custom', 'adv'),
	array('menu_misc_link', 'misc_link'),
	array('menu_plugins', 'plugins'),
);

if(file_exists($menudir = ROOT_PATH.'./source/admincp/menu')) {
	$adminextend = $adminextendnew = array();
	if(file_exists($adminextendfile = ROOT_PATH.'./data/cache/cache_adminextend.php')) {
		@include $adminextendfile;
	}
	$menudirhandle = dir($menudir);
	while($entry = $menudirhandle->read()) {
		if(!in_array($entry, array('.', '..')) && preg_match("/^menu\_([\w\.]+)$/", $entry, $entryr) && substr($entry, -4) == '.php' && strlen($entry) < 30 && is_file($menudir.'/'.$entry)) {
			@include_once $menudir.'/'.$entry;
			$adminextendnew[] = $entryr[1];
		}
	}
	if($adminextend != $adminextendnew) {
		@unlink($adminextendfile);
		if($adminextendnew) {
			require_once libfile('function/cache');
			writetocache('adminextend', getcachevars(array('adminextend' => $adminextendnew)));
		}
		unset($_G['lang']['admincp']);
	}
}

$menu['tools'] = array(
	array('menu_tools_updatecaches', 'tools_updatecache'),
	array('menu_misc_announce', 'announce'),
	array('menu_logs', 'logs'),
	array('menu_misc_cron', 'misc_cron'),
	array('menu_spider', 'misc_spider'),
	$isfounder ? array('menu_tools_fileperms', 'tools_fileperms') : null,
	$isfounder ? array('menu_tools_filecheck', 'checktools_filecheck') : null,
);
if($isfounder) {
	$topmenu['founder'] = '';

	$menu['founder'] = array(
		array('menu_setting_mail', 'setting_mail'),
		array('menu_db', 'db_runquery')
	);

	$menu['uc'] = array();
}

if(!isfounder() && !isset($GLOBALS['admincp']->perms['all'])) {
	$menunew = $menu;
	foreach((array)$menu as $topkey => $datas) {
		if($topkey == 'index') {
			continue;
		}
		$itemexists = 0;
		foreach((array)$datas as $key => $data) {
			if(array_key_exists($data[1], $GLOBALS['admincp']->perms)) {
				$itemexists = 1;
			} else {
				unset($menunew[$topkey][$key]);
			}
		}
		if(!$itemexists) {
			unset($topmenu[$topkey]);
			unset($menunew[$topkey]);
		}
	}
	$menu = $menunew;
}

?>